FBL.ns ( function () 
{
	with ( FBL )
	{ 
		const Cc = Components.classes;
		const Ci = Components.interfaces;

		Firebug.FireliweTab = extend ( Firebug.Module, 
		{ 
			initialize: function ()
			{
				Firebug.NetMonitor.NetInfoBody.addListener ( this );
			},

			shutdown: function ()
			{
				Firebug.NetMonitor.NetInfoBody.removeListener ( this );
			},

			// Listener for NetInfoBody.
			initTabBody: function ( infoBox, file )
			{
				if ( ! file.jsonObject )
				{
					try
					{
						eval ( file.responseText );
						file.jsonObject = ajax_response;
						file.liweSize = file.responseText.length;
					}
					catch ( e )
					{
						return;
					}
				}

				if ( file.jsonObject )
				{
					Firebug.NetMonitor.NetInfoBody.appendTab ( infoBox, "Fireliwe", "FireLiWE" );
					var doc = infoBox.ownerDocument;
					var ss = createStyleSheet ( doc, 'chrome://fireliwe/skin/fireliwe.css' );
					addStyleSheet ( doc, ss );
				}
			},

			destroyTabBody: function ( infoBox, file )
			{
			},

			updateTabBody: function ( infoBox, file, context )
			{
				var tab = infoBox.selectedTab;

				if ( tab.dataPresented || !hasClass ( tab, "netInfoFireliweTab" ) )
					return;

				tab.dataPresented = true;

				var tabBody = getElementByClass ( infoBox, "netInfoFireliweText" );

				var content = {
					err_code: file.jsonObject [ 'err_code' ],
					err_descr: file.jsonObject [ 'err_descr' ],
					size: file.liweSize
				};

				delete file.jsonObject [ 'err_code' ];
				delete file.jsonObject [ 'err_descr' ];

				this.tpl.content.replace ( { content: content }, tabBody, this.tpl );

				var jsonDiv = getElementByClass ( tabBody, 'fireliwe-content' );

				Firebug.JSONViewerModel.Preview.render ( jsonDiv, file, context );
			}
		}); 

		Firebug.FireliweTab.tpl = domplate (
		{
			content:
				DIV ( { 'class': 'fireliwe-container' },
					DIV ( { 'class': 'fireliwe-liwe-logo' },
						A ( { 'href': 'http://www.liwe.org/', 'target': '_blank' },
							IMG ( { 'src': 'chrome://fireliwe/content/liwe.png' } )
						)
					),
					DIV ( { 'class': 'fireliwe-title' },
						SPAN ( { 'class': 'fireliwe-title-name' }, 'Code' ),
						SPAN ( { 'class': 'fireliwe-title-value' }, '$content.err_code' )
					),
					DIV ( { 'class': 'fireliwe-title' },
						SPAN ( { 'class': 'fireliwe-title-name' }, 'Description' ),
						SPAN ( { 'class': 'fireliwe-title-value' }, '$content.err_descr' )
					),
					DIV ( { 'class': 'fireliwe-os3-logo' },
						A ( { 'href': 'http://www.os3.it/', 'target': '_blank' },
							IMG ( { 'src': 'chrome://fireliwe/content/os3.png' } )
						)
					),
					DIV ( { 'class': 'fireliwe-data' },
						SPAN ( { 'class': 'fireliwe-data-name' }, 'Size' ),
						SPAN ( { 'class': 'fireliwe-data-value' }, '$content.size bytes' )
					),
					DIV ( { 'class': 'fireliwe-content' }, 'Loading...' )
				)
		} );

		Firebug.registerModule ( Firebug.FireliweTab );
	}
} );
